#include <iostream>
#include <string.h>
#include <vector>

int OriginMap[5][5] = {
	{0, 1, 1, 0, 1 },
	{1, 0, 1, 0, 1 },
	{1, 1, 0, 1, 1 },
	{0, 0, 1, 0, 1 },
	{1, 1, 1, 1, 0 } };

int Map[5][5];

void ResetMap()
{
	memcpy(Map, OriginMap, sizeof(int[5][5]));
}

std::vector<int> Path;
int offset = 0;

bool DFS(int index)
{
	bool found = false;
	for (int i = 0; i < 5; ++i)
	{
		int ii = (i + offset) % 5;
		if (Map[index][ii] == 1)
		{
			Map[index][ii] = 0;
			Map[ii][index] = 0;
			DFS(ii);
		}
	}

	Path.insert(Path.begin(), {index});
}

int main()
{
	for (int start = 0; start < 2; ++start)
	{
		for (offset = 0; offset < 5; ++offset)
			{
				ResetMap();
				Path.clear();
				DFS(start);
				
					for (auto i : Path)
					{
						std::cout << i + 1 << '\t';
					}
					std::cout << std::endl;
				
			}
	}

	return 0;
}
